const http = require('http')
const fs = require('fs')
const path = require('path')

http.createServer((req, res)=>{
    console.log('request come', req.url)
    const host = req.headers.host
    if (req.url==='/'){
        const html = fs.readFileSync(path.resolve(__dirname,'test.html'))

        console.log(host)
        if (host==='localhost:8888'){
            console.log('为localhost:7777添加cookie')
            res.writeHead(200,{
                'content-type':'text/html',
                'Set-Cookie': [
                    'id=123; max-age=200;',
                    'username1=http://localhost:7777;domain=http://localhost;',
                    'username2=http://localhost:8888;domain=http://localhost;'
                ]
            })
        }
        res.end(html)
    }
}).listen(8888)

console.log('server listening 8888')
